package com.openweixin.sheknows.util;

/**
 * 通过数据库生成代码的工具类
 * 注意事项：无
 * @author 刘思作
 * @version 1.0.0 2014-04-01
 * @since 1.0.0
 */

public class CoderGenerate {
	public static String getType(String type){
		if(type.startsWith("int") || type.startsWith("tinyint") ||type.startsWith("decimal")||type.startsWith("float")){
			return "number";
		}
		if(type.startsWith("char") || type.startsWith("var") || type.equals("text")) {
			return "String";
		}
		if(type.startsWith("date") ) {
			return "date";
		}
		if(type.equals("timestamp")){
			return "java.sql.Timestamp";
		}
		return "";
	}
	public static String tableToClass(String name){
		return tableToClass(name,false);
	}
	public static String tableToClass(String name,boolean isTable){
		String[] parts = name.split("_");
		String newName = "";
		if(isTable) {
			for (int i = 0; i < parts.length; i++) {
				newName += parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1);
			}
		}else{
			if(parts.length == 1){
				return parts[0];
			}
			for (int i = 0; i < parts.length; i++) {
				if(i > 0)
					newName += parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1);
				else 
					newName += parts[i];
			}
		}
		
		return newName;
	}
}
